package com.hongyang.servlet.baby;

import com.alibaba.fastjson.JSONObject;
import com.hongyang.service.BabyService;
import com.hongyang.service.impl.BabyServiceImpl;
import com.hongyang.vo.ResultEnum;
import com.hongyang.vo.ResultVO;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/hr/newbaby/delnewbabydangan")
public class Delete extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        res.setCharacterEncoding("UTF-8");
        res.setContentType("text/html;charset=UTF-8");

        ResultVO<String> resultVO=null;

        String id = req.getParameter("id");

        if (StringUtils.isBlank(id)){
            resultVO = ResultVO.failed(ResultEnum.PARAMS_FAILED);
        }else{
            BabyService service=new BabyServiceImpl();
            resultVO=service.deleteByPrimaryKey(id);
        }

        PrintWriter out= res.getWriter();
        String jsonString = JSONObject.toJSONString(resultVO);
        out.println(jsonString);
        out.flush();
        out.close();
    }
}
